package com.zhiyou100.cudr;

import com.zhiyou100.dao.StudentDao;
import com.zhiyou100.entityclass.Student;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @packageName: ${NAME}
 * @className: ${PACKAGE_NAME}
 * @Description: TODO
 * @author: yang
 * @date: 7/20/20
 */
@WebServlet(name = "delOne", urlPatterns = "/delOne")
public class DelOne extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        // 设定编码集
        response.setContentType("text/html;charset=UTF-8");
        // 设定类型



        String sid = request.getParameter("sid");

        if (new Student().sidFlag(sid)){
            // 合理
            StudentDao studentDao = new StudentDao();
            boolean b = studentDao.delOne(Integer.parseInt(sid));

            request.setAttribute("delFlag",b);

            request.getRequestDispatcher("/jsp/delOne.jsp").forward(request,response);
        }else {
            // 不合理
            request.setAttribute("delFlag",false);

            request.getRequestDispatcher("/jsp/delOne.jsp").forward(request,response);
        }



    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
